
#include "graphe.h"
#include "noeud.h"
#include "arc.h"
#include "dynamicarray.h"
#include <stdio.h>

#define PRINT_CELL(cell) printf("%d\n",*((int*)(cell)))

int main(int argc, char** argv)
{
    Graphe graphe;
    graphe_initialize(&graphe);
    graphe_addNode(&graphe,"Paris");
    graphe_addNode(&graphe,"Lyon");
    graphe_addNode(&graphe,"Marseille");
    graphe_addArcByValue(&graphe,"Paris","Lyon",600);
    graphe_addArcByValue(&graphe,"Paris","Marseille",900);
    graphe_addArcByValue(&graphe,"Lyon","Paris",650);
    graphe_addArcByValue(&graphe,"Lyon","Marseille",300);
    graphe_addArcByValue(&graphe,"Marseille","Lyon",350);
    graphe_addArcByValue(&graphe,"Marseille","Paris",950);
    graphe_print(&graphe);
    graphe_removeNodeByValue(&graphe,"Lyon");
    graphe_print(&graphe);
    graphe_clear(&graphe);
    printf("Hello World!\n");
    return 0;
}

int isEqual_int(void* a, void* b)
{
    int *i1 = (int*) a, *i2 = (int*) b;
    return ((*i1) == (*i2));
}

void testList()
{
    List list;
    DynamicArray dynamicArray;
    Cell *cell;
    const Object obj = object_getInt();
    int tab[10] = {0,1,2,7,4,5,6,7,8,9};
    int* ptab[10];
    int i;

    list_initialize(&list,&obj,1);
    dynamicArray_initialize(&dynamicArray);
    for(i = 0; i < 10; i++)
    {
        ptab[i] = list_insertLast(&list,&i);
        dynamicArray_inserLast(&dynamicArray,&tab[i]);
    }

    printf("Premier : ");
    PRINT_CELL(list_getFirstValue(&list));
    PRINT_CELL(dynamicArray.array[0]);
    printf("Dernier : ");
    PRINT_CELL(list_getLastValue(&list));
    PRINT_CELL(dynamicArray.array[dynamicArray.count - 1]);

    for(i = 0; i < list_getCount(&list); i++)
    {
        printf("liste: ");
        PRINT_CELL(list_getValueAt(&list,i));
        printf("tableau dynamique: ");
        PRINT_CELL(dynamicArray.array[i]);
    }
    printf("Suppression de 5\n");
    list_remove(&list,ptab[5]);
    dynamicArray_removeAt(&dynamicArray,5);
    for(i = 0; i < list_getCount(&list); i++)
    {
        printf("liste: ");
        PRINT_CELL(list_getValueAt(&list,i));
        printf("tableau dynamique: ");
        PRINT_CELL(dynamicArray.array[i]);
    }
    printf("Suppression de 0\n");
    list_remove(&list,ptab[0]);
    dynamicArray_removeFirst(&dynamicArray);
    for(i = 0; i < list_getCount(&list); i++)
    {
        printf("liste: ");
        PRINT_CELL(list_getValueAt(&list,i));
        printf("tableau dynamique: ");
        PRINT_CELL(dynamicArray.array[i]);
    }

    printf("Affichage de 7\n");
    list_getFirstOf(&list,&tab[7],&cell);
    PRINT_CELL(cell->value);

    printf("Suppression du premier 7\n");
    list_removeFirstOf(&list,&tab[7]);
    for(i = 0; i < list_getCount(&list); i++)
    {
        PRINT_CELL(list_getValueAt(&list,i));
    }

    printf("Suppression du dernier 7\n");
    list_removeFirstOf(&list,&tab[7]);
    for(i = 0; i < list_getCount(&list); i++)
    {
        PRINT_CELL(list_getValueAt(&list,i));
    }

    printf("Suppression du dernier : ");
    PRINT_CELL(list_getLastValue(&list));

    list_remove(&list,ptab[9]);
    for(i = 0; i < list_getCount(&list); i++)
    {
        PRINT_CELL(list_getValueAt(&list,i));
    }

    list_clear(&list);
    dynamicArray_clear(&dynamicArray);
}
